package io.terminus.paas.profiler.dubbo.filter

import com.alibaba.dubbo.common.Constants
import com.alibaba.dubbo.common.extension.Activate
import com.alibaba.dubbo.rpc.Filter
import com.alibaba.dubbo.rpc.Invocation
import com.alibaba.dubbo.rpc.Invoker
import com.alibaba.dubbo.rpc.Result
import io.terminus.paas.profiler.monitor.InFluxDBMonitor
import io.terminus.paas.profiler.monitor.Monitor

/**
 * Created by gengrong on 16/5/17.
 */
@Activate(group = arrayOf(Constants.PROVIDER))
open class ProfilerDubboFilter : Filter {

    private val monitor: Monitor = InFluxDBMonitor();

    override fun invoke(invoker: Invoker<*>, invocation: Invocation): Result? {
        monitor.invokerBefore(invocation);
        val result = invoker.invoke(invocation);
        monitor.invokerAfter(result);
        return result
    }

}